package io.demo_6_序列化;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main1(String[] args)throws Exception {
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("d:/1.txt"));
        Stu s1=new Stu(1,"a1",1.78);
        Stu s2=new Stu(2,"a2",1.88);
        Stu.age=23;
        //方案一：直接写对象
//        oos.writeObject(s1);
//        oos.writeObject(s2);
        //方案二：放入集合后，再序列化
        List list=new ArrayList<>();
        list.add(s1);
        list.add(s2);
        oos.writeObject(list);
        oos.close();
    }

    public static void main(String[] args)throws Exception {
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("d:/1.txt"));
        List list=(List)ois.readObject();
        System.out.println(list);
        System.out.println(Stu.age);

        ois.close();
    }
}
